package com.jia.interviewPro;

public class Pro1001 {
    public void merge(int[] A, int m, int[] B, int n) {
        int k = m + n - 1, i = m - 1, j = n - 1;
        while(i >= 0 && j>=0) {
            if(A[i]>B[j]) {
                A[k--] = A[i--];
            }else {
                A[k--] = B[j--];
            }
        }
        while(j >=0) {
            A[k--] = B[j--];
        }
    }
    public void merge2(int[] A, int m, int[] B, int n) {
        int j = m - 1;
        for(int i = 0; i < n; i++) {
            int k = j;
            while(k >= 0 && A[k] > B[i]) {
                A[k+1] = A[k];
                --k;
            }
            A[k+1] = B[i];
            ++j;
        }
    }
}
